mod plugins;
mod input_map;
mod systems;
mod components;
mod state;
mod resources;
mod database;
mod board;
mod settings;
mod solve;
mod utils;

use bevy::prelude::*;
use bevy_kira_audio::prelude::*;
use input_map::{default_input_map, Action};
use leafwing_input_manager::{action_diff::ActionDiffEvent, plugin::InputManagerPlugin, prelude::ActionState};
use plugins::{config, performance_matrix, ui};
use state::AppState;
use systems::{level::{setup_database, setup_level}, render::{animate_player, set_windows_icon, setup_camera}, ui::{setup_button, setup_hud}};
#[bevy_main]
fn main() {
    let mut app = App::new();

    println!("Hello, world!");

    app.add_plugins((
        DefaultPlugins.set(WindowPlugin{
            primary_window: Some(Window{
                title: "推箱子".to_string(),
                ..default()
            }),
            ..default()
        }),
        AudioPlugin,
        InputManagerPlugin::<Action>::default(),
    ))
    .init_state::<AppState>()
    .enable_state_scoped_entities::<AppState>();

    app.add_systems(PreStartup, (setup_camera,setup_database));
    app.add_systems(Startup, (set_windows_icon,setup_level));
    app.add_systems(FixedUpdate, animate_player);

    app.add_plugins((
        performance_matrix::plugin,
        ui::plugin,
        config::plugin
    ));
    app.init_resource::<ActionState<Action>>()
        .insert_resource(default_input_map())
        .add_event::<ActionDiffEvent<Action>>();

    app.run();
}
